<?php
include_once XXF_MAIL;
class Apps_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
		$type=!empty($_POST['type'])?$_POST['type']:false;
		$type=!empty($xxfget['type'])?$xxfget['type']:$type;
		if(!$type){
		    echo "404 not found";
		}elseif($type=="resultQuery"){
		    $ty=!empty($xxfget['ty'])?$xxfget['ty']:false;
		    if(!$ty){
		        $this->show($type);
		    }elseif($ty=="query"){
		        $sname=$_POST['sname'];
		        $cname=$_POST['cname'];
		        echo xdb::getInstance()->getjson("select kcname,score from ksscore where trim(sname) like '$sname' and trim(cname) like '$cname' and kid=2");
		    }
		}elseif($type=="appsLotteryDraw"){
		    $ty=!empty($xxfget['ty'])?$xxfget['ty']:false;
		    if(!$ty){
		        $this->show($type);
		    }elseif($ty=='updata'){
				$id=$_POST['id'];
				$result=xdb::getInstance()->getvar("select max(result)+1 from tempcj");
				xdb::getInstance()->query("update tempcj set status='0',result=$result where id=$id");
				echo $result;
			}elseif($ty=='init'){
				xdb::getInstance()->query("update tempcj set status='1',result=0");
				echo "抽奖已初始化";
			}
		}elseif($type=='mail'){
		    $username=$_POST['username'];
		    if(!trim($username)){
		        echo "请输入有效用户名！";
		        exit();
		    }
		    $password=xdb::getInstance()->getvar("select password from user where username=$username");
		    if($password){
		        $smtpserver = "smtp.sina.com";//SMTP服务器
		        $smtpserverport =25;//SMTP服务器端口
		        $smtpusermail = "xuxiufeng003@sina.com";//SMTP服务器的用户邮箱
		        $smtpemailto = "275494961@qq.com";//发送给谁
		        $smtpuser = "xuxiufeng003@sina.com";//SMTP服务器的用户帐号，注：部分邮箱只需@前面的用户名
		        $smtppass = "newplayer003";//SMTP服务器的用户密码
		        $mailtitle = "安培中心矿业学校信息平台邮件";//邮件主题
		        $mailcontent = "<h1>$password</h1>";//邮件内容
		        $mailtype = "HTML";//邮件格式（HTML/TXT）,TXT为文本邮件
		        //************************ 配置信息 ****************************
		        $smtp = new Smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
		        $smtp->debug = false;//是否显示发送的调试信息
		        $state = $smtp->sendmail($smtpemailto, $smtpusermail, $mailtitle, $mailcontent, $mailtype);
		        if($state){
		            echo "请在你QQ邮箱查看密码！";
		        }else{
		            echo "请联系管理员！";
		        }
		    }else{
		        echo "无效用户名！";
		    }
		}
    }
}